package com.wwy.order.mapper;



import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.common.domain.PageResult;
import com.wwy.order.domain.BaseDO;
import com.wwy.order.domain.ReportOrder;
import com.wwy.order.domain.vo.QueryOrderPageReq;
import com.wwy.order.mybatis.BaseMapperX;
import com.wwy.order.mybatis.LambdaQueryWrapperX;
import org.apache.ibatis.annotations.Mapper;

import java.util.List;
import java.util.Objects;

/**
 * @author 王伟羽
 * @date 2024/12/11 15:13
 */
@Mapper
public interface ReportOrderMapper extends BaseMapperX<ReportOrder> {
    default PageResult<ReportOrder> selectPage(QueryOrderPageReq reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<ReportOrder>()
                .eq(Objects.nonNull(reqVO.getOrderStatus()),ReportOrder::getOrderStatus,reqVO.getOrderStatus())
                .eq(StringUtils.isNotBlank(reqVO.getOrderNumber()),ReportOrder::getOrderNumber,reqVO.getOrderNumber())
                .eq(BaseDO::getCreator,reqVO.getCreator())
                .orderByDesc(ReportOrder::getCreateTime));
    }

    default List<ReportOrder> selectList(ReportOrder reqVO) {
        return selectList(new LambdaQueryWrapperX<ReportOrder>()
                .eq(Objects.nonNull(reqVO.getOrderStatus()),ReportOrder::getOrderStatus,reqVO.getOrderStatus())
                .eq(StringUtils.isNotBlank(reqVO.getOrderNumber()),ReportOrder::getOrderNumber,reqVO.getOrderNumber())
                .eq(StringUtils.isNotBlank(reqVO.getCreator()),BaseDO::getCreator,reqVO.getCreator())
                .orderByDesc(ReportOrder::getCreateTime));
    }

    default int updateByOrderId(String id, ReportOrder update) {
        return update(update, new QueryWrapper<ReportOrder>()
                .eq("order_number", id));
    }
    default int updateByPayOrderId(String id, ReportOrder update) {
        return update(update, new QueryWrapper<ReportOrder>()
                .eq("pay_order_id", id));
    }
    default int updateByIdAndTime(String orderNumber, Integer status, ReportOrder updateObj) {
        return update(updateObj, new LambdaQueryWrapperX<ReportOrder>()
                .eq(ReportOrder::getOrderNumber, orderNumber).eq(ReportOrder::getOrderStatus, status));
    }


}
